package com.xjtu.chapter06.ex6_2;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/18 17:17
 */
public class Process {
    void Proc(int sel){
        System.out.println("******in case "+sel+" ******");
        if(sel==0){
            //没有异常
            System.out.println("no exception caught");
            return;
        }else if(sel==1){
            try{
                int i=0;
                int j=5/i;//除数为零
                throw new ArithmeticException();//显式地抛出ArithmeticException异常对象
            }catch (ArithmeticException e){
                System.out.println(e.toString());
            }
        }else if(sel==2){
            try{
                int array[] = new int[4];
                array[5]=5;
                throw new ArrayIndexOutOfBoundsException();//显式地抛出ArrayIndexOutOfBoundsExceptionn异常对象
            }catch (ArrayIndexOutOfBoundsException e){
                System.out.println(e.toString());
            }
        }
    }
}

